package com.ymatou.iapi.payment.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.payment.parameter.RegisterFqlBean;
import com.ymatou.iapi.payment.service.RegisterFqlCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*分期乐注册
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RegisterFql{
	private static RegisterFqlBean registerfqlBean;
	private static RegisterFqlCall registerfqlCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分期乐注册");
	}

	@Before
	public void caseUp() {
		registerfqlBean=new RegisterFqlBean();
		registerfqlCall=new RegisterFqlCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(registerfqlCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	//需要手工验证 查看日志分期乐发送报文
	public void Tc_RegisterFql_001() {
		Logger.start(true,"分期乐注册成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			registerfqlBean.setUserId(uid);
			registerfqlBean.setMobile("19999999998");
			registerfqlCall.setData(registerfqlBean);
			registerfqlCall.callService();			
//			Logger.verifyNotNull(registerfqlCall.getString("FqlToken"), "FqlToken");
			Logger.verifyEquals("true", registerfqlCall.getString("IsSuccess"), "IsSuccess");
			//"FqlState":2
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//分期乐限流
	public void Tc_RegisterFql_002() {
		Logger.start(true,"5分钟内重复调用分期乐注册返回缓存");
		try {
			registerfqlBean.setUserId(1);
			registerfqlBean.setMobile("19999999999");
			registerfqlCall.setData(registerfqlBean);
			registerfqlCall.callService();			
			String ft = registerfqlCall.getString("FqlToken");
			registerfqlCall.callService();			
			String ft2 = registerfqlCall.getString("FqlToken");
			Logger.verifyEquals(ft, ft2, "验证一致");
			Logger.verifyEquals("true", registerfqlCall.getString("IsSuccess"), "IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}